﻿using LCL.CodeHelper;
using LCL.IBuilder;
using LCL.LData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace LCL.Builder.SimpleFactory
{
    /// <summary>
    /// 简单工厂
    /// </summary>
    public partial class ProjectBuilder : BaseProjectBuilder, IProjectBuilder
    {
        string ModelGuid = Guid.NewGuid().ToString().ToUpper();
        string DALGuid = Guid.NewGuid().ToString().ToUpper();
        string IDALGuid = Guid.NewGuid().ToString().ToUpper();
        string DALFactoryGuid = Guid.NewGuid().ToString().ToUpper();
        string WebApiGuid = Guid.NewGuid().ToString().ToUpper();
        string WebMvcGuid = Guid.NewGuid().ToString().ToUpper();
        string SlhGuid = Guid.NewGuid().ToString().ToUpper();

        public ProjectBuilder()
        {
            Name = "简单工厂";
        }
        public void Generate()
        {
            BuilderModel();
            BuilderIDAL();
            BuilderDALFactory();

            BuilderDAL();

            BuilderWebAPI();

            //BuilderWebMvc();

            BuilderSlh();

            CodeLib();
            MSBuild();
        }

        #region BuilderSlh
        private void BuilderSlh()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine(" ");
            builder.AppendLine("Microsoft Visual Studio Solution File, Format Version 12.00");
            builder.AppendLine("# Visual Studio 2012");
            builder.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + NameSpace + ".Model\", \"Model\\" + NameSpace + ".Model.csproj\", \"{" + ModelGuid + "}\" ");
            builder.AppendLine("EndProject ");
            builder.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + NameSpace + ".IDAL\", \"IDAL\\" + NameSpace + ".IDAL.csproj\", \"{" + IDALGuid + "}\" ");
            builder.AppendLine("EndProject ");
            builder.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + NameSpace + ".DALFactory\", \"DALFactory\\" + NameSpace + ".DALFactory.csproj\", \"{" + DALFactoryGuid + "}\" ");
            builder.AppendLine("EndProject ");
            builder.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + NameSpace + ".DAL\", \"DAL\\" + NameSpace + ".DAL.csproj\", \"{" + DALGuid + "}\" ");
            builder.AppendLine("EndProject ");
            builder.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"WebAPI\", \"WebAPI\\WebAPI.csproj\", \"{" + WebApiGuid + "}\" ");
            builder.AppendLine("EndProject ");
            builder.AppendLine("Global ");
            builder.AppendLine("	GlobalSection(SolutionConfigurationPlatforms) = preSolution ");
            builder.AppendLine("		Debug|Any CPU = Debug|Any CPU ");
            builder.AppendLine("		Release|Any CPU = Release|Any CPU ");
            builder.AppendLine("	EndGlobalSection ");
            builder.AppendLine("	GlobalSection(ProjectConfigurationPlatforms) = postSolution ");
            builder.AppendLine("		{" + ModelGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU ");
            builder.AppendLine("		{" + ModelGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU ");
            builder.AppendLine("		{" + ModelGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU ");
            builder.AppendLine("		{" + ModelGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU ");

            builder.AppendLine("		{" + IDALGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU ");
            builder.AppendLine("		{" + IDALGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU ");
            builder.AppendLine("		{" + IDALGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU ");
            builder.AppendLine("		{" + IDALGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU ");

            builder.AppendLine("		{" + DALFactoryGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU ");
            builder.AppendLine("		{" + DALFactoryGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU ");
            builder.AppendLine("		{" + DALFactoryGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU ");
            builder.AppendLine("		{" + DALFactoryGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU ");

            builder.AppendLine("		{" + DALGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU ");
            builder.AppendLine("		{" + DALGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU ");
            builder.AppendLine("		{" + DALGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU ");
            builder.AppendLine("		{" + DALGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU ");

            builder.AppendLine("	EndGlobalSection ");
            builder.AppendLine("	GlobalSection(SolutionProperties) = preSolution ");
            builder.AppendLine("		HideSolutionNode = FALSE ");
            builder.AppendLine("	EndGlobalSection ");
            builder.AppendLine("EndGlobal ");


            string filename = CodeCommon.DesktopDirectory + NameSpace + @"/" + NameSpace + ".sln";
            CodeCommon.CreateFiles(filename, builder.ToString());

           
        }

        #endregion

    }
}
